package com.jyu.hakkatranslation.controller;



import com.jyu.hakkatranslation.dao.AnswerMapper;
import com.jyu.hakkatranslation.pojo.Answer;
import com.jyu.hakkatranslation.pojo.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("mp3_id")
public class CommentController {

    @Autowired
    private AnswerMapper answerMapper;

    @RequestMapping("/to_answer")
    public Msg getAnswerWithJson(
            @RequestParam(value = "pn",defaultValue = "1")Integer pn, HttpSession session){
        /*Integer mp3id = (Integer) session.getAttribute("mp3Id");
        if(mp3id==null){
            mp3id=1;
        }
        System.out.println(mp3id);
        //这不是一个分页查询
        //引入PageHelper分页插件
        //在查询之前只需要调用，传入代码，以及每一页的大小
        String orderBy="love_number desc";
        //按照love字段降序排序
        PageHelper.startPage(pn,5,orderBy);
        List<Answer> answers = answerMapper.answerByMp3Id(mp3id);
        //使用pageInfo包装查询后的结果，只需要将pageInfo交给页面就可以了。
        //封装了详细的分页信息,包括有我们查询出来的的结果
        PageInfo page=new PageInfo(answers,5);
        return Msg.success().add("pageInfo",page);*/
        return Msg.fail();
    }

    @RequestMapping("/love")
    public String  love(int loveid){
        System.out.println(loveid);
        answerMapper.addLove_number(loveid);
        return "温馨提示：刷新页面以更新支持数哦~";
    }

}
